import time

from base.Base import Base
from selenium.webdriver.common.by import By
class Page(Base):
    #定位器
    login_loc=(By.XPATH,'//*[@id="com_userbar"]/ul/li[4]/div/a')
    zhuce_loc=(By.ID,'TANGRAM__PSP_5__regLink')
    denglu_loc=(By.XPATH,'//span[@id="login_btn"]')
    username_loc=(By.NAME,'userName')
    password_loc=(By.XPATH,'//starts-with[@name,"password"]')
    loginbtn_loc=(By.XPATH,'//input[@type="submit" and @value="登录"]')
    sousuokuang_loc=(By.XPATH,'/html/body/div[3]/div/div[1]/div[1]/div/div/div[2]/div/div[1]/form/input[1]')
    sousuobtn_loc=(By.XPATH,'//*[@id="wd1"]')
    tiebabtn_loc=(By.CLASS_NAME,'search_btn.search_btn_enter_ba.j_enter_ba')
    dy1_loc = (By.CSS_SELECTOR,'.card_title_fname')
    dy2_loc=(By.LINK_TEXT,'需要 加精 置顶 推首页 的联系吧主')
    #封装页面
    def login(self):
        self.click(self.login_loc)
    def zhuce(self):
        self.click(self.zhuce_loc)
    def denglu(self):
        self.click(self.denglu_loc)
    def username(self):
        self.send_keys(self.username_loc,"白衣渡江35")
    def password(self):
        self.send_keys(self.password_loc,"LMQ123123")
    def loginbtn(self):
        self.click(self.loginbtn_loc)
    def sousuokuang(self):
        self.click(self.sousuokuang_loc)
    def sousuobtn(self):
        self.send_keys(self.sousuobtn_loc,"游戏")
    def tiebabtn(self):
        self.click(self.tiebabtn_loc)
    def dy1(self):
        self.text(self.dy1_loc)
    def dy2(self):
        self.text(self.dy2_loc)
    #业务逻辑
    def yewu_baidutieba(self):
        self.goto("https://tieba.baidu.com/")
        #隐式等待
        self.driver.implicitly_wait(2)
        self.sousuokuang()
        print(self.dy1())
        #强制等待
        time.sleep(2)
        self.sousuobtn()
        self.tiebabtn()